package com.cn.boot.student.service.team.impl;

import com.cn.boot.student.entity.DispatchRecordEntity;
import com.cn.boot.student.entity.TeamUserRelationEntity;
import com.cn.boot.student.mapper.DispatchRecordMapper;
import com.cn.boot.student.service.team.ITeamDisPatch;
import com.cn.boot.student.util.CommonResult;
import com.cn.boot.student.util.Tool;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.List;

/**
 * 小组调度记录逻辑实现层
 * @author luosir
 */
@Service
public class TeamDispatchRelationServiceImpl implements ITeamDisPatch {
    @Autowired
    private DispatchRecordMapper dispatchRecordMapper;
    /**
     * 调度记录列表
     *
     * @param dispatchRecordEntity
     * @return
     */
    @Override
    public CommonResult findAll(DispatchRecordEntity dispatchRecordEntity) {
        //得到调度记录总数
        Integer count = dispatchRecordMapper.getCount(dispatchRecordEntity);
        PageHelper.startPage(Tool.toPageNum(dispatchRecordEntity.getPageNum()), Tool.toPageSize(dispatchRecordEntity.getPageSize()));
        List<DispatchRecordEntity> list = dispatchRecordMapper.findAll(dispatchRecordEntity);
        if(list.size() == 0){
            return CommonResult.failed( "当前暂无数据！！！");
        }
        PageInfo<DispatchRecordEntity> pageInfo = new PageInfo<>(list);
        HashMap<String, Object> map = new HashMap<>();
        map.put("pageInfo", pageInfo);
        map.put("count", count);
        return CommonResult.success(map, "查询成功！！！");
    }

    /**
     * 调度记录删除
     *
     * @param id
     * @return
     */
    @Override
    public CommonResult del(Integer id) {
        Integer result = dispatchRecordMapper.del(id);
        if(result == 0){
            return CommonResult.failed("删除失败！！！");
        }
        return CommonResult.success(result,"删除成功！！！");
    }


}
